﻿/// <reference path="../jquery.d.ts"/>
/// <reference path="../jquerymobile.d.ts"/>
/// <reference path="../geo.core.ts" />

Geo.Core.OnAfterInitialize.add(function () {
    $('#btnNext').bind('click', function () {
        Geo.Core.Navigation.GoToAction($('#txtLookup').val());
        return false;
    });

    $('#lblStatus').html((Geo.Core.Current.IsOnline ? 'Online' : 'Offline') + ' Mode');

    if (Geo.Core.LogEntryRepository.Count() > 0){
        $('#divLogEntries').show();
        var tbl : HTMLElement =  $('#tbodyLogEntries')[0];
        var logEntries : Geo.Interfaces.ILogEntry[] = Geo.Core.LogEntryRepository.GetList();
        for (var index in logEntries){
            var logEntry : Geo.Interfaces.ILogEntry = logEntries[index];
            var dataRowCols = '<td>' + logEntry.LogEntryLid + '</td>';
            dataRowCols += '<td>' + logEntry.PrivateKey + '</td>';
            dataRowCols += '<td><a href="#" onclick="Geo.Core.Navigation.GoToActionEdit(' + logEntry.LogEntryLid + ');">' + Geo.Core.EnumLabelProvider.GetActionTypeLabel(logEntry.ActionType) + '</a></td>';

            dataRowCols += '<td><a href="#" onclick="Geo.Core.Navigation.GoToGeocacheEdit(' + logEntry.LogEntryLid + ');">'
            if (logEntry.CacheCode){
               dataRowCols += Geo.String.IsNull(logEntry.CacheCode,'');
            }else{
               dataRowCols += 'Add Cache'
            }
            dataRowCols += '</a></td>';

            dataRowCols += '<td><a href="#" onclick="Geo.Core.Navigation.GoToUserEdit(' + logEntry.LogEntryLid + ');">'
            if (logEntry.UserInteractedWith){
               dataRowCols += Geo.String.IsNull(logEntry.UserInteractedWith,'');
            }else{
               dataRowCols += 'Add Interaction'
            }
            dataRowCols += '</a></td>';

           
            dataRowCols += '<td><a href="#" onclick="Geo.Core.Navigation.GoToLocationEdit(' + logEntry.LogEntryLid + ');">'
            if (logEntry.Coordinates&&logEntry.Coordinates.Latitude&&logEntry.Coordinates.Longitude){
                 dataRowCols += logEntry.Coordinates.Latitude +', '+ logEntry.Coordinates.Longitude;
            }else{
                dataRowCols += 'Add Coordinates'
            }
            dataRowCols += '</a></td>';

            var dataRow: string = '<tr>' + dataRowCols + '</tr>'; 
            $("#tbodyLogEntries").append(dataRow);
        }


    }
});
